/* 字符串 */
let str: string = '123' // '123'
/* 数组 */
let list: number[] = [1, 2, 3] // [1, 2, 3]
/* 元组 */
let x: [string, number] = ['10', 2] // ['10', 2]
/* 枚举 */
enum Color {Red = 'red', Green = 'green', Blue = 'blue'}
let c: Color = Color.Blue // blue
/* 任意值 */
let anyNum: any = 123
/* 空值 */
let voidData: void = undefined // 只能为它赋予undefined和null
/* null 和 undefined */
let u: undefined = undefined
let n: null = null
/* 类型断言 */
let someValue: string = 'this is a string'
let stringLen: number = (<string>someValue).length
/* 对象解构 */
let {a, b}: {a: string, b: number} = {
  a: '123',
  b: 123
}
let {a: aaa, b: bbb}: {a: string, b: number} = { // 重命名解构
  a: '123',
  b: 123
}
/* 定义默认值 */
function keepWholeObject(wholeObject: {a?: string, b?: number}) {
  let {a = 100, b = 1001} = wholeObject
  // console.log(a, b) // 100 1001
}
keepWholeObject({ a: undefined, b: undefined})
/* 接口 */
interface LabeledValue {
  readonly name: string, // 只读属性
  label: string,
  area?: number // 可选属性
}
let myObj = {
  label: '111',
  name: '222'
}
function printLabel (labelObject: LabeledValue) {
  // console.log(labelObject.label) // 111
}
printLabel(myObj)
/* 只读属性 */
let testArr: number[] = [1, 2, 3]
let readonlyArr: ReadonlyArray<number> = testArr
/* 函数类型 */
interface SearchFunc { // 定义函数的参数和返回值类型
  (source: string, subString: string): boolean;
}
let mySearch: SearchFunc = function(source: string, subString: string) {
  if (source === '1' && subString === '1') {
    return true
  }
  return false
}
// console.log(mySearch('1', '1')) // true
